
import GeneralSheet from './generaSheet.js'
export default class XLG {
	getxlgJson(fileName) {
		return {
			content: luckysheet.getAllSheets(),
			title: fileName
		}
	}
	getAllSheets() {
		return luckysheet.getAllSheets()
	}
	constructor(xlg) {
		this.title = ""
		this.content = []
		this.XLG(xlg)
	}

	XLG(xlg = null) {
		if (xlg) {
			if (typeof xlg === 'string') {
				xlg = JSON.parse(xlg);
			}
			this.xlgJson = xlg
			this.title = xlg.title;
			for (let i in xlg.content) {
				let cont = xlg.content[i];
				let sheet = this.createSimpleSheet(cont.name)
				sheet.xlgObj = this
				sheet.xlgJson = xlg
				sheet.color = cont.color
				sheet.index = cont.index
				sheet.order = parseInt(cont.order)
				sheet.status = cont.status
				sheet.config = cont.config
				sheet.data = cont.data
				sheet.celldata = cont.celldata
				sheet.calcChain = cont.calcChain
				sheet.jfgird_select_save = cont.jfgird_select_save
				sheet.luckysheet_select_save = cont.luckysheet_select_save
				sheet.visibledatarow = cont.visibledatarow
				sheet.visibledatacolumn = cont.visibledatacolumn
				sheet.ch_width = cont.ch_width
				sheet.rh_height = cont.rh_height
				sheet.luckysheet_selection_range = cont.luckysheet_selection_range
				sheet.zoomRatio = cont.zoomRatio
			}
		}

	}
	createSimpleSheet(sheetName) {
		const optional = this.content.filter(item => {
			return item.name === sheetName
		})
		if (Object.keys(optional).length) {
			alert("Sheet页" + sheetName + "已存在，不允许重复添加")
		} else {
			let sheet = new GeneralSheet(sheetName);
			this.content.push(sheet)
			return sheet
		}
	}
	getSheet(index) {

		const sheet = this.content.filter(item => {
			return (item.name === index || item.index === index || item.order == index)
		})
		if (!sheet) {
			alert("不存在名称为【" + index + "】的DataTable")
		}
		return sheet[0]

	}
}
